<template>
	<view class="container container24934">

		<view class="flex diygw-col-24 flex-direction-column">
			<view class="diygw-tabs text-center solid-bottom justify-center scale-title small-border tabs-title">
				<view class="diygw-tab-item tabs-item-title" :class="index == tabsIndex ? ' cur text-orange' : ''"
					v-for="(item, index) in tabsDatas" :key="index" @click="changeTabs($event,item.id)"
					:data-index="index"> <text v-if="item.icon" :class="item.icon"></text> {{ item.text }} </view>
			</view>
			<view class="">
				<view v-if="tabsIndex == 0" class="flex-sub"> </view>
				<view v-if="tabsIndex == 1" class="flex-sub"> </view>
			</view>
		</view>

		<view v-for="(item,index) in datarows" :key="index" 
		class="flex flex-wrap diygw-col-24 flex-direction-column flex-clz" @click="forword(item.id)">
			<view class="flex diygw-col-24 items-center flex-nowrap flex1-clz">
				<view class="flex flex-wrap diygw-col-8 flex-direction-column">
					<image src="/static/global/cat.jpg" class="response diygw-col-24" mode="widthFix"></image>
				</view>
				<view class="flex flex-wrap diygw-col-16 flex-direction-column flex3-clz">
					<view class="flex diygw-col-24 items-center flex-nowrap">
						<view class="flex diygw-col-8">
							<view class="diygw-tag margin-xs xs radius-sm diygw-line-orange">
								<text> {{ transform(item.publishType) }} </text>
							</view>
						</view>
						<view class="diygw-col-15 text-clz"> {{ item.petName }} </view>
					</view>
					<view class="flex flex-wrap diygw-col-24 flex-direction-column flex4-clz">
						<view class="diygw-col-24 text2-clz"> {{ contentTransform(item.remark) }} </view>
					</view>
					<view class="flex diygw-col-24 items-center flex-nowrap">
						<view class="flex diygw-col-4">
							<view class="diygw-avatar xs margin-xs radius bg-none">
								<image mode="aspectFit" class="diygw-avatar-img radius" src="/static/address.png">
								</image>
							</view>
						</view>
						<view class="diygw-col-19 text1-clz"> {{ item.address }} </view>
					</view>
				</view>
			</view>
		</view>

		<view class="clearfix"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//用户全局信息
				userInfo: {},
				//页面传参
				globalOption: {},
				//自定义全局变量
				globalData: {},
				tabsDatas: [{
						text: `寻找爱宠`,
						icon: ``,
						id: 0,
					},
					{
						text: `寻找主人`,
						icon: ``,
						id: 1,
					}
				],
				tabsLeft: 0,
				tabsWidth: 0,
				tabsItemWidth: 0,
				tabsIndex: 0,
				inputFocus: false,
				input: '',
				page: 1,
				size: 10,
				datarows: [],
				total: 0,
			};
		},
		onShow() {
			this.setCurrentPage(this);
		},
		onLoad(option) {
			this.setCurrentPage(this);
			if (option) {
				this.setData({
					globalOption: this.getOption(option)
				});
			}

			this.init();
		},
		methods: {
			async init() {
				// this.resultApi()
				this.getListByTypeId(0)
			},
			changeTabs(evt, id) {
				let {
					index
				} = evt.currentTarget.dataset;
				if (index == this.tabsIndex) return;
				this.setData({
					tabsIndex: index
				});
				this.total = 0
				this.datarows = []
				this.page = 1
				this.getListByTypeId(id)
			},
			forword(id) {
				uni.navigateTo({
					url: '/pages/user/select/details?id='+id
				})
			},

			async getListByTypeId(type) {
				const page = this.page
				const size = this.size
				const http_url = '/publisher-selectpet/page/' + page + '/' + size
				const data = {
					"publisherType": type
				}
				const header={
					'content-type': 'application/json;charset=UTF-8',
					"Token":uni.getStorageSync('token')
				}
				const result = await this.$http.get(http_url, data,header)
				console.log(result)
				const code = result.code
				
				if (code == 200) {
					const data = result.data.records
					this.count = result.data.total
					this.datarows = this.datarows.concat(data)
				}
			},
			contentTransform(content) {
				const maxLength = 73; // 指定的字符数
				if (content.length <= maxLength) {
					return content; // 如果内容长度小于等于指定字符数，则直接返回原内容
				} else {
					return content.substring(0, maxLength) + '...'; // 使用 substring 方法截取指定字符数，并添加省略号
				}
			},
			transform(type){
				return type==0?'寻找爱宠':'寻找主人'
			}
		},
		onReachBottom() {

			if (this.datarows.length < this.count) {
				this.page++;
				this.getListByTypeId(this.tabsIndex)
			}


		},
		onPullDownRefresh() {
			this.init()
		},
	};
</script>

<style lang="scss" scoped>
	.flex-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.input-clz {
		background-color: #f4f4f4;
		margin-left: 10rpx;
		width: calc(87.5% - 10rpx - 10rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
	}

	.flex1-clz {
		padding-top: 10rpx;
		border-bottom-left-radius: 12rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		border-top-right-radius: 12rpx;
		margin-right: 10rpx;
		margin-left: 10rpx;
		box-shadow: 0rpx 2rpx 6rpx rgba(31, 31, 31, 0.16);
		overflow: hidden;
		width: calc(100% - 10rpx - 10rpx) !important;
		border-top-left-radius: 12rpx;
		margin-top: 10rpx;
		border-bottom-right-radius: 12rpx;
		margin-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.flex3-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.text-clz {
		font-weight: bold;
		font-size: 28rpx !important;
	}

	.flex4-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
		height: 120rpx !important;
	}

	.flex7-clz {
		padding-top: 40rpx;
	}

	.text2-clz {
		color: #858585;
	}

	.text1-clz {
		color: #8d8d8d;
	}

	.container24934 {
		padding-left: 0px;
		padding-right: 0px;
	}

	.container24934 {}
</style>